#include "myparkingwidget.h"
#include "ui_myparkingwidget.h"
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
#include "loginwidget.h"

myParkingWidget::myParkingWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::myParkingWidget)
{
    ui->setupUi(this);
    initWindow();
}

myParkingWidget::~myParkingWidget()
{
    delete ui;
}

/**
 * @brief 初始化窗体
 */
void myParkingWidget::initWindow()
{
    this->setWindowTitle("我的车位");

    QSqlQuery query;
    query.prepare("SELECT * FROM parking_apply WHERE apply_username = :apply_username");
    query.bindValue(":apply_username", LoginWidget::userName);
    if (!query.exec())
    {
        qDebug() << query.lastError();
    }
    else
    {
        if (query.next())
        {
            QString position = query.value(2).toString();
            QString type = query.value(3).toString();
            QString canCharge = query.value(4).toString();
            QString size = query.value(5).toString();
            QString carNum = query.value(6).toString();
            QString isPay = query.value(7).toString();
            ui->label_position->setText(QString("车位位置：%1").arg(position));
            ui->label_type->setText(QString("车位类型：%1").arg(type));
            ui->label_can_charge->setText(QString("可充电：%1").arg(canCharge));
            ui->label_size->setText(QString("车位大小：%1").arg(size));
            ui->label_car_num->setText(QString("登记车牌号：%1").arg(carNum));
            ui->label_is_pay->setText(isPay);
        }
    }
}
